package com.example.backend.mapper;


import com.example.backend.entity.Shop;
import org.apache.ibatis.annotations.*;
import org.springframework.stereotype.Repository;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

@Repository
public interface ShopMapper {
    @Delete("delete from shop where id = #{id}")
    int deleteShop(Integer id);
    @Insert("insert into shop(shopname,pwd,checked,score,phone,address,state,picture,income,gratuity) values(#{shopname},#{pwd},#{checked},#{score},#{phone},#{address},#{state},#{picture},#{income},#{gratuity})")
    int addShop(Shop shop);
    @Select("select * from shop where id = #{id}")
    Shop selectShopById(Integer id);

    @Select("select * from shop where shopname = #{shopname}")
    Shop selectByShopname(String shopname);

    @SelectProvider(type = ShopMapperProvider.class, method = "getSelectShopsSql")
    ArrayList<Shop> selectAll(Shop shop);

    @UpdateProvider(type = ShopMapperProvider.class,method = "getUpdateShopSql")
    int updateShop(Shop shop);

    @Select("select * from shop")
    ArrayList<Shop> shopGetPage();
    
    //商家总数
    @Select("select count(*) from shop")
    int countShops();
    
    // 获取商家地理分布数据
    @Select("select address, count(*) as count from shop group by address")
    List<Map<String, Object>> getShopGeoDistribution();

    @UpdateProvider(type = ShopMapperProvider.class,method = "getUpdateShopScoreSql")
    int updateShopScore(Integer id);
}
